import gap.maven.script.components.api.POMArtifactFile;
import gap.maven.script.components.api.ArtifactFileFactory;
import gap.maven.script.components.api.POMArtifactFile;
import gap.maven.script.components.api.ScriptContext;
import gap.maven.script.components.api.ExtractorPattern;
import gap.maven.script.components.api.ArtifactFile;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;

final Log log = binding.getVariable("log");
final ScriptContext context = binding.getVariable("context");
final ArtifactFileFactory factory = context.lookup(ScriptContext.ARTIFACT_FILE_FACTORY_KEY);

POMArtifactFile file = factory.createPOMFile("org.apache.maven", "maven-artifact", "2.2.1");
if(file.download()) {
	ArtifactFile jarFile = file.getMainArtifact("jar");
	if(jarFile.download())
	{
		jarFile.copy("./");
		jarFile.extract(new File("./"), new ExtractorPattern().setPath("META-INF"));
	}
	
	// assertions
	if(!(new File("./META-INF")).isDirectory())
	{
		throw new MojoExecutionException("File extraction failed.")
	}
	
	(new File("./" + jarFile.file.name)).delete();
	File metaDir = (new File("./META-INF"));
	for(File f : metaDir.listFiles())
	{
		f.delete();
	}
	metaDir.delete();	
}
